package test;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
interface IntegerStack{
	public Integer push(Integer item);
	public Integer pop();
	public Integer peek();
	public boolean empty();
	public int size();
}

class ArrayListIntegerStack implements IntegerStack{
	private List<Integer> list;
	public ArrayListIntegerStack(){
		list=new ArrayList<Integer>();
	}
	
	@Override
	public Integer push(Integer item){
		if(item==null)return null;
		list.add(item);
		return item;
	}
	@Override
	public Integer pop(){
		if(list.size()==0)return null;
		return list.remove(list.size()-1);
	}
	@Override
	public Integer peek(){
		if(list.size()==0)return null;
		return list.get(list.size()-1);
	}
	@Override
	public boolean empty(){
		return list.size()==0?true:false;
	}
	@Override
	public int size(){
		return list.size();
	}

	@Override
	public String toString() {
		return list.toString();
	}
	
}
public class Main {

	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		ArrayListIntegerStack list=new ArrayListIntegerStack();
		int m=in.nextInt();
		for(int i=0;i<m;i++){
			Integer s=in.nextInt();
			System.out.println(list.push(s));
		}
		System.out.println(list.peek()+","+list.empty()+","+list.size());
		System.out.println(list);
		int x=in.nextInt();
		for(int j=0;j<x;j++){
			System.out.println(list.pop());
		}
		System.out.println(list.peek()+","+list.empty()+","+list.size());
		System.out.println(list);
	}

}
